 <html>
<head>

<script type="text/javascript" src="build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="build/event/event-min.js"></script>
<script type="text/javascript" src="build/connection/connection-min.js"></script>

<script type="text/javascript" src="init.js"></script>
<script type="text/javascript" src="dasParsers.js"></script>
<script type="text/javascript" src="classes.js"></script>
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript" src="karyotypeStructureFunctions.js"></script>

<script>
function makeSpecieRequest(){
	var url = YAHOO.dasBrowser.genome.karyotypeStructure.proxyUrl + "?" + YAHOO.dasBrowser.proxy.parameters.source + "=" + YAHOO.dasBrowser.genome.karyotypeStructure.referenceUrl + "dsn";
    var request = YAHOO.util.Connect.asyncRequest('GET', url, specieRequestCallback);
}


var specieRequestCallback = {
    success:function(o){
		var dasUrl = YAHOO.dasBrowser.genome.karyotypeStructure.referenceUrl;
		var ensemblDsnResults = YAHOO.dasBrowser.genome.karyotypeStructure.dsn.parseEnsemblDsn(o.responseXML, YAHOO.dasBrowser.genome.karyotypeStructure.dsn.selectedDsn.id);
		//YAHOO.dasBrowser.util.displayObjProp(ensemblDsnResults.allEnsemblDsn);
		//console.log(o.responseXML);
		var specieMenu = new Array();
		for(var i = 0; i < ensemblDsnResults.allEnsemblDsn.length; i++){
			if(ensemblDsnResults.allEnsemblDsn[i].sourceType == 'karyotype'){
				var splitReferenceUrl = ensemblDsnResults.allEnsemblDsn[i].referenceUrl.split(dasUrl);
				var sourceSpecie = ensemblDsnResults.allEnsemblDsn[i].sourceSpecie;
				var sourceRelease = ensemblDsnResults.allEnsemblDsn[i].sourceRelease;
				var menuText = sourceSpecie + ' ' + sourceRelease;
				var menuValue = splitReferenceUrl[1];
				
				var specieRow = new Object();
				specieRow.text = menuText;
				specieRow.value = menuValue;
				specieMenu.push(specieRow);
				//console.log(menuText);
				//console.log(menuValue);
			}
		}
		printResult(specieMenu);
    },
    failure:function(o){
		console.log("failure");
	}
}

function printResult(specieMenu){
	for (var i = 0; i < specieMenu.length; i++) {
			console.log(i+"TEXT: "+specieMenu[i].text);
			console.log(i+"VALUE: "+specieMenu[i].value);
		}	
}


YAHOO.util.Event.addListener(window, 'load', makeSpecieRequest);

</script>
    </head>
    <body>
    </body>
</html>
